import time
import unittest
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
from ddt import ddt, data, unpack
from read.tools import read_csv


def load_test_data():
    with open('a3mall.csvv', 'r', encoding='utf-8-sig') as f:
        return list(csv.DictReader(f))  #将每一行转换为字典。


# all_data = load_test_data()
# #存储所有测试数据

@ddt  # 支持json/yaml
class a3mall(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Edge()
        self.driver.get('http://10.59.9.14:7003/')
        self.driver.maximize_window()
        self.driver.implicitly_wait(15)

    def tearDown(self):
        self.driver.quit()

    @data(*read_csv('data.csv'))  #
    @unpack  # 将字典数据解包为单独参数
    def test_01(self, username, password, remark):
        if remark == 1:
            self.driver.find_element(By.XPATH, '//a[contains(text(),"登录")]').click()
            self.driver.find_element(By.NAME, 'username').send_keys(username)
            self.driver.find_element(By.NAME, 'password').send_keys(password)
            time.sleep(8)
            self.driver.find_element(By.CLASS_NAME, 'finish-btn').click()
            time.sleep(2)

        else:
            self.driver.find_element(By.XPATH, '//a[contains(text(),"登录")]').click()
            self.driver.find_element(By.NAME, 'username').send_keys(username)
            self.driver.find_element(By.NAME, 'password').send_keys(password)
            time.sleep(8)
            self.driver.find_element(By.CLASS_NAME, 'finish-btn').click()
            time.sleep(2)